package com.chencong.online.function;

import com.chencong.online.bean.WebLogEventBean;
import org.apache.flink.api.common.functions.MapFunction;

import java.text.SimpleDateFormat;

/**
 * @program: user-behavior-analysis-online
 * @ClassName WebLogEventMapFunc
 * @description:
 * @author: chencong
 * @create: 2021-12-23 09:54
 **/
public class WebLogEventMapFunc implements MapFunction<String, WebLogEventBean> {
    @Override
    public WebLogEventBean map(String value) throws Exception {
        String[] split = value.split(" ");
        String ip = split[0];
        String date = split[3];
        //格式化时间转换为timestamp
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy:hh:mm:ss");
        long timestamp = simpleDateFormat.parse(date).getTime();
        String method = split[5];
        String url = split[6];
        return new WebLogEventBean(ip,timestamp,method,url);
    }
}
